package elion.com.theElion.activityMain;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zzhoujay.richtext.RichText;

import java.lang.reflect.InvocationTargetException;

import elion.com.elion.R;
import elion.com.theElion.util.ReflectUtil;

/**
 * Created by xiaon on 2017/6/9.
 */

public class ShowContentActivity extends AppCompatActivity {
    private LinearLayout linearLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_content);
        linearLayout = (LinearLayout) findViewById(R.id.ll_service_all);
        ViewHole viewHolder = new ViewHole();
        viewHolder.title = (TextView) findViewById(R.id.sc_sevice_title);
        viewHolder.content = (TextView) findViewById(R.id.sc_sevice_text);
        viewHolder.answer = (TextView) findViewById(R.id.sc_sevice_answer);
        viewHolder.date = (TextView) findViewById(R.id.sc_sevice_date);

        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();

        String name[] = bundle.getStringArray("name");
        for (int i = 0; i < name.length; i++)
        {
            try
            {
                ReflectUtil.useSetMethod(viewHolder, name[i], bundle.getString(name[i]));
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }

    class ViewHole {

        private TextView content;
        private TextView date;
        private TextView answer;
        private TextView title;

        public TextView getContent() {
            return content;
        }

        public void setContent(String content)
        {
            RichText.from(content).into(this.content);
//            this.content.setText(content);
        }

        public TextView getDate() {
            return date;
        }

        public void setDate(String date) {
            this.date.setText(date);
        }

        public TextView getAnswer() {
            return answer;
        }

        public void setAnswer(String answer) {
            RichText.from(answer).into(this.answer);
//            this.answer.setText(answer);
        }

        public TextView getTitle() {
            return title;
        }

        public void setTitle(String title)
        {
            RichText.from(title).into(this.title);

//            this.title.setText(title);
        }
    }
}
